#include "index/attribute_index/attribute_indexer.h"

namespace hawking {
namespace indexlib {

void AttributeIndexer::Filter(
    SegmentContext* segment_ctx,
    const util::FilterColumn& filter_field,
    util::ColumnType field_type,
    int32_t field_id,
    bool is_where) {
    std::vector<DocContext>& doc_ctxs = *(segment_ctx->MutableDocContext());
    for (auto& doc_ctx : doc_ctxs) {
        if (doc_ctx.filtered) {
            continue;
        }

        util::FieldValue* index_value = doc_ctx.GetField(field_id);
        if (!index_value) {
            continue;
        }

        AttributeFilter attr_filter(
            filter_field.column_value(),
            *index_value,
            filter_field.action(),
            field_type,
            is_where);
        
        if (attr_filter.DoFilter()) {
            doc_ctx.filtered = true;
            segment_ctx->DecrRelateCount();
        }
    }
}

}
}